import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home'
import About from '../views/About'
import Personal from '../views/personal'
import Toastmaster from '../views/toastmaster'
import Login from '../Login'
import NewPronen from '../Sign.vue/newPronen'
import Laboy from '../views/laboy'
// import Houtai from '../componnet/houtai'
import Article from '../views/Article'
import HostDetail from '../views/toastmaster/HostDetail'
import Company from '../Sign.vue/company'
import store from '../store' ;
import Dynamgongsi from '../views/personal/dynamgongsi'
import Cehuashi from '../views/personal/cehuashi'
import Newpersonal from '../views/personal/newpersonal'
import JoinUs from '../views/JoinUs'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Laboy',
    component: Laboy,
    redirect:'home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: Home,
        meta: {
          isLogin: false
        }
      },
      {
        path: 'about',
        name: 'About',
        component: About,
        meta: {
          isLogin: true
        }
      },
      {
        path: 'personal',
        name: 'Personal',
        component: Personal,
        meta: {
          isLogin: true
        }
      },
      {
        path: 'cehuashi',
        name: 'Cehuashi',
        component: Cehuashi,
        meta: {
          isLogin: true
        }
      },
      {
        path: 'dynamgongsi',
        name: 'Dynamgongsi',
        component: Dynamgongsi,
        meta: {
          isLogin: true
        }
      },
      {
        path: 'newpersonal',
        name: 'Newpersonal',
        component: Newpersonal,
        meta: {
          isLogin: true
        }
      },
      {
        path: 'toastmaster',
        name: 'Toastmaster',
        component: Toastmaster,
        meta: {
          isLogin: true
        }
      },
      {
        path: 'article',
        name: 'Article',
        component: Article,
        meta: {
          isLogin: true
        }
      },
      {
        path: 'hostdetail',
        name: 'HostDetail',
        component: HostDetail,
        meta: {
          isLogin: true
        }
      },
      {
        path: 'joinus',
        name: 'JoinUs',
        component: JoinUs,
        meta: {
          isLogin: true
        }
      }
    ],
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: {
      isLogin: false
    }
  },
  {
    path: '/newPronen',
    name: 'NewPronen',
    component: NewPronen,
    meta: {
      isLogin: false
    }
  },
  // {
  //   path:'/houtai',
  //   name:"Houtai",
  //   component:Houtai
  // },
  {
    path:'/glypz',
    name:'Glypz',
    component:()=>import('../houtai/glypz')
  },
  {
    path:'/glysz',
    name:'Glysz',
    component:()=>import('../houtai/glypz/glysz')
  },
  {
    path:"/zhr",
    name:"Zcrgl",
    component:()=>import('../houtai/zhrgl')
  },
  {
    path: '/company',
    name: 'Company',
    component: Company,
    meta: {
      isLogin: false
    }
  }


]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


router.beforeEach ((to,from,next)=>{
  // console.log(to)
  // if(to.fullPath=="/personal"){
  //   if(localStorage.getItem('new')==1){
  //     next()
  //   }else if(localStorage.getItem('new')==2){
  //     next('/dynamgongsi')
  //   }
  // }
  if(to.meta.isLogin){
    if(store.state.LoginModule.token){
      // 如果用户登录倒转对应页面
     
      next()
    }else{
      //跳转登录页
      next({
        path:'/login'
      })
    }
  }else{
    next()
  }
})

export default router
